package com.linx.system.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.linx.common.core.domain.R;
import com.linx.common.core.validate.AddGroup;
import com.linx.common.core.validate.EditGroup;
import com.linx.common.excel.utils.ExcelUtil;
import com.linx.common.idempotent.annotation.RepeatSubmit;
import com.linx.common.log.annotation.Log;
import com.linx.common.log.enums.BusinessType;
import com.linx.common.mybatis.core.page.PageQuery;
import com.linx.common.mybatis.core.page.TableDataInfo;
import com.linx.common.translation.annotation.TranslationBatch;
import com.linx.common.web.core.BaseController;
import com.linx.system.domain.bo.ProblemFeedbackBo;
import com.linx.system.domain.vo.ProblemFeedbackVo;
import com.linx.system.service.IProblemFeedbackService;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 问题反馈
 *
 * @author linx
 * @date 2024-12-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/feedback")
public class ProblemFeedbackController extends BaseController {

    private final IProblemFeedbackService problemFeedbackService;

    /**
     * 查询问题反馈列表
     */
    @SaCheckPermission("system:feedback:list")
    @GetMapping("/list")
    @TranslationBatch(resClass = ProblemFeedbackVo.class)
    public TableDataInfo<ProblemFeedbackVo> list(ProblemFeedbackBo bo, PageQuery pageQuery) {
        return problemFeedbackService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出问题反馈列表
     */
    @SaCheckPermission("system:feedback:export")
    @Log(title = "问题反馈", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ProblemFeedbackBo bo, HttpServletResponse response) {
        List<ProblemFeedbackVo> list = problemFeedbackService.queryList(bo);
        ExcelUtil.exportExcel(list, "问题反馈", ProblemFeedbackVo.class, response);
    }

    /**
     * 获取问题反馈详细信息
     *
     * @param problemFeedbackId 主键
     */
    @SaCheckPermission("system:feedback:query")
    @GetMapping("/{problemFeedbackId}")
    @TranslationBatch(resClass = ProblemFeedbackVo.class)
    public R<ProblemFeedbackVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long problemFeedbackId) {
        return R.ok(problemFeedbackService.queryById(problemFeedbackId));
    }

    /**
     * 新增问题反馈
     */
    @SaCheckPermission("system:feedback:add")
    @Log(title = "问题反馈", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ProblemFeedbackBo bo) {
        return toAjax(problemFeedbackService.insertByBo(bo));
    }

    /**
     * 修改问题反馈
     */
    @SaCheckPermission("system:feedback:edit")
    @Log(title = "问题反馈", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ProblemFeedbackBo bo) {
        return toAjax(problemFeedbackService.updateByBo(bo));
    }

    /**
     * 删除问题反馈
     *
     * @param problemFeedbackIds 主键串
     */
    @SaCheckPermission("system:feedback:remove")
    @Log(title = "问题反馈", businessType = BusinessType.DELETE)
    @DeleteMapping("/{problemFeedbackIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] problemFeedbackIds) {
        return toAjax(problemFeedbackService.deleteWithValidByIds(List.of(problemFeedbackIds), true));
    }
}
